
import { delUser, getUsers } from '../../../../server/controllers/adminCon';
import api from '../../http/apis/apis';

export default {
    namespaced: true,
    state: {
        userData: {
            users: [],
            total: 0,
            currentPage: 1,
            pageSize: 3,
            totalPages: 0
        }
    },
    mutations: {
        changePageSize(state, val) {
            state.userData.pageSize = val
        },
        // previousPage(state) {
        //     if (state.userData.currentPage > 1) {
        //         state.userData.currentPage--
        //     }
        // },
        // nextPage(state) {
        //     if (state.userData.currentPage < state.userData.totalPages) {
        //         state.userData.currentPage++
        //     }
        // },
        changeCurrentPage(state, val) {
            state.userData.currentPage = val
        }
    },
    actions: {
        async addUser(context, addUserData) {
            let { data } = await api.adminsApi.addUser(addUserData)
            // console.info(data)
            return data
        },
        async getUsers(context, searchType = "") {
            let userData = context.state.userData
            let sendData = { userData, searchType: searchType }
            let { data } = await api.adminsApi.getUsers(sendData)
            context.state.userData = data.userData
            console.info(data.userData)
        },
        async delUser(context, _id) {
            let { data } = await api.adminsApi.delUser({ _id: _id })
            return data
        },
        async getClients(context, _id) {
            let { data } = await api.adminsApi.getClients({ _id: _id })
            return data
        },
        async modUser(context,newUserData){
            let {data}=await api.adminsApi.modUser(newUserData)
            return data
        }
    },
    model: {}
}